package com.example.othree.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.othree.entity.CropsYieldYearData;
import com.example.othree.entity.WeatherHistoryData;
import com.example.othree.mapper.CropsYieldYearDataMapper;
import com.example.othree.mapper.WeatherHistoryDataMapper;
import com.example.othree.mapper.WheatCornGrowthYearMapper;
import com.example.othree.service.WeatherHistoryDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zogran
 * @since 2024-11-12
 */
@Service
public class WeatherHistoryDataServiceImpl extends ServiceImpl<WeatherHistoryDataMapper, WeatherHistoryData> implements WeatherHistoryDataService {
    @Resource
    WeatherHistoryDataMapper weatherHistoryDataMapper;
    @Resource
    WheatCornGrowthYearMapper wheatCornGrowthYearMapper;
    @Override
    public IPage PageList(IPage<WeatherHistoryData> page, Wrapper wrapper) {
        return weatherHistoryDataMapper.PageList(page,wrapper);
    }

    @Override
    public IPage WeatherPageList(IPage<WeatherHistoryData> page,
                                 String city,
                                 String district,
                                 String year,
                                 String crop,
                                 String startPeriod, String endPeriod){
        return weatherHistoryDataMapper.WheatGrowthYearPageList(page, city, district, year, crop, startPeriod, endPeriod);
    }

    @Override
    public List<WeatherHistoryData> WeatherList(String city, String district, String year, String crop, String startPeriod, String endPeriod) {

        String startDate = wheatCornGrowthYearMapper.TimeByYearForCrop(startPeriod, district, year, crop);
        String endDate = wheatCornGrowthYearMapper.TimeByYearForCrop(endPeriod, district, year, crop);
        return weatherHistoryDataMapper.WheatGrowthYearList(city, district, year, crop, startDate, endDate);
    }
}
